package es.islomar.poc.googleapitranslate;

import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;

/**
 * https://code.google.com/p/google-api-translate-java/
 * 
 * @author islomar
 * 
 */
public class GoogleApiTranslateMain {

	// public static void main(String[] args) throws GoogleAPIException {
	// // Set the HTTP referrer to your website address.
	// GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
	//
	// // Set the Google Translate API key
	// // See:
	// http://code.google.com/apis/language/translate/v2/getting_started.html
	// GoogleAPI.setKey("AIzaSyCSWWj2kKUhbN5FsKKo58iVupAPT1h37JM");
	//
	// String translatedText = Translate.DEFAULT.execute("Bonjour le monde",
	// Language.FRENCH, Language.ENGLISH);
	//
	// System.out.println(translatedText);
	// }

	@Test(enabled=false)
	public void testHttpReferrerRequired() throws Exception {

		System.out.println("testHttpReferrerRequired");
		try {
			Translate.translate("Hello world", Language.ENGLISH, Language.ARABIC);
			fail("Should have thrown an error as HTTP referrer is not set.");
		} catch (Exception e) {
			assertEquals("[google-api-translate-java] Referrer is not set. Call setHttpReferrer().", e.getMessage());
		}
	}
	
	@Test(enabled=false)
	public void testTranslate() throws Exception {
		System.out.println("testTranslate");

		Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");

		assertEquals("مرحبا العالم", Translate.translate("Hello world", Language.ENGLISH, Language.ARABIC));
		assertEquals("世界您好", Translate.translate("Hello world", Language.ENGLISH, Language.CHINESE));
		assertEquals("Bonjour le monde", Translate.translate("Hello world", Language.ENGLISH, Language.FRENCH));
		assertEquals("Hallo Welt", Translate.translate("Hello world", Language.ENGLISH, Language.GERMAN));
		assertEquals("नमस्कार दुनिया", Translate.translate("Hello world", Language.ENGLISH, Language.HINDI));
		assertEquals("Ciao mondo", Translate.translate("Hello world", Language.ENGLISH, Language.ITALIAN));
		assertEquals("こんにちは世界", Translate.translate("Hello world", Language.ENGLISH, Language.JAPANESE));
		assertEquals("여보세요 세계", Translate.translate("Hello world", Language.ENGLISH, Language.KOREAN));
		assertEquals("Olá mundo", Translate.translate("Hello world", Language.ENGLISH, Language.PORTUGUESE));
		assertEquals("Привет мир", Translate.translate("Hello world", Language.ENGLISH, Language.RUSSIAN));
		assertEquals("Hola Mundo", Translate.translate("Hello world", Language.ENGLISH, Language.SPANISH));
		assertEquals("Hello dinja", Translate.translate("Hello world", Language.ENGLISH, Language.MALTESE));
		assertEquals("สวัสดีโลก", Translate.translate("Hello world", Language.ENGLISH, Language.THAI));
		assertEquals("Merhaba Dünya", Translate.translate("Hello world", Language.ENGLISH, Language.TURKISH));
		assertEquals("Hola Mundo", Translate.translate("Привет мир", Language.RUSSIAN, Language.SPANISH));
		assertEquals("Ciao mondo", Translate.translate("Hallo welt", Language.GERMAN, Language.ITALIAN));
		assertEquals("D'accord", Translate.translate("Ok", Language.ENGLISH, Language.FRENCH));

		assertEquals("Bonjour tout le monde", Translate.translate("Привет мир", Language.AUTO_DETECT, Language.FRENCH));
	}

	@Test(enabled=false)
	public void testExample() throws Exception {

		System.out.println("testExample");
		Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
		assertEquals("Hello world", Translate.translate("Bonjour le monde", Language.FRENCH, Language.ENGLISH));
	}

}
